#include "widget.h"
#include "./ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    int v = TBattery::kInitPowerLevel;
    ui->horizontalSlider->setValue(v);
    ui->battery->setPowerLevel(v);
    QString str = QString::asprintf("当前电量：%d %%", v);
    ui->labInfo->setText(str);

    connect(ui->horizontalSlider, SIGNAL(valueChanged(int)), this, SLOT(on_horizontalSlider_valuedChanged(int)));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_horizontalSlider_valuedChanged(int value)
{
    qDebug() << "value = " << value;
    ui->battery->setPowerLevel(value);
    QString str = QString::asprintf("当前电量：%d %%", value);
    ui->labInfo->setText(str);
}

